package com;

/**
 * Created with IntelliJ IDEA.
 * Description:镜像二叉树
 * User: YJ
 * Date: 2024-4-27
 * Time: 15:43
 */
public class MirrorTest {

    /**
     * 输入：{8,6,10,5,7,9,11}
     * 输出：{8,10,6,11,9,7,5}
     * @param args
     */
    public static void main(String[] args) {
        TreeNode pRoot = new TreeNode(8);
        TreeNode s1 = new TreeNode(6);
        TreeNode s2 = new TreeNode(10);
        TreeNode s3 = new TreeNode(5);
        TreeNode s4 = new TreeNode(7);
        TreeNode s5 = new TreeNode(9);
        TreeNode s6 = new TreeNode(11);
        pRoot.left = s1;
        pRoot.right = s2;
        s1.left = s3;
        s1.right = s4;
        s2.left = s5;
        s2.right = s6;
        TreeNode treeNode = Mirror(pRoot);
        treeOrderTest treeOrderTest = new treeOrderTest();
        treeOrderTest.sequenceOrder(treeNode);
    }
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     *
     * @param pRoot TreeNode类
     * @return TreeNode类
     */
    public static TreeNode Mirror (TreeNode pRoot) {
        // write code here
        //空树返回
        if (pRoot == null) return null;
        //递归子树
        TreeNode left = Mirror(pRoot.left);
        TreeNode right = Mirror(pRoot.right);
        //交换
        pRoot.left = right;
        pRoot.right = left;
        return pRoot;
    }
}
